//
//  HTLeftMenuDrawView.m
//  HT_aigongzuo
//
//  Created by 周昭 on 16/10/12.
//  Copyright © 2016年 HT_Technology. All rights reserved.
//

#import "HTLeftMenuDrawView.h"

@implementation HTLeftMenuDrawView

- (void)drawBezierPathWithControlP:(CGPoint)controlP currentP:(CGPoint)currentP endP:(CGPoint)endP rightP:(CGPoint)rightP leftP:(CGPoint)leftP lineWidth:(CGFloat)lineWidth lineColor:(UIColor *)lineColor
{
    self.controlP = controlP;
    self.currentP = currentP;
    self.endP = endP;
    self.rightP = rightP;
    self.leftP = leftP;
    self.lineWidth = lineWidth;
    self.lineColor = lineColor;
    
    [self setNeedsDisplay];
}

/**
 *  来画贝塞尔曲线
 */
- (void)drawRect:(CGRect)rect
{
    // 上下文
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    
    // 设置线宽
    CGContextSetLineWidth(ctx, self.lineWidth);
    
    // 设置颜色
    [self.lineColor set];
    
    // 设置线段头尾部的样式
    CGContextSetLineCap(ctx, kCGLineCapRound);
    
    // 中间的控制点
    CGPoint control = self.controlP;
    
    // 当前点
    CGPoint current = self.currentP;
    CGContextMoveToPoint(ctx, current.x, current.y);
    
    // 结束点
    CGPoint end = self.endP;
    
    // 贝塞尔曲线
    CGContextAddQuadCurveToPoint(ctx, control.x, control.y, end.x, end.y);
    
    // 创建右上转角点
    CGContextMoveToPoint(ctx, self.rightP.x, self.rightP.y);
    
    CGContextAddLineToPoint(ctx, self.endP.x, self.endP.y);
    
    // 创建左下转角点
    CGContextMoveToPoint(ctx, self.leftP.x, self.leftP.y);
    
    CGContextAddLineToPoint(ctx, self.endP.x, self.endP.y);
    // 渲染
    CGContextStrokePath(ctx);
}
@end
